import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import px2viewport from "postcss-px-to-viewport";
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
import path from 'node:path'
import UnoCSS from 'unocss/vite'
import fs from 'fs'
// https://vite.dev/config/
export default defineConfig({
  plugins: [UnoCSS({
    configFile: 'unocss.config.js',
  }), vue(), AutoImport({
    resolvers: [VantResolver()],
  }),
  Components({
    resolvers: [VantResolver()],
  }),

  ],
  css: {
    postcss: {
      plugins: [px2viewport({ viewportWidth: 768 })], // 示例：适配 Vant 组件库
    }
  },
  resolve: {
    alias: {
      '@': path.join(__dirname, './src'),
      '~': path.join(__dirname, './src/assets'),
      '~root': path.join(__dirname, '.'),
    },
  },
  server: {
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
        secure: false
      }
    },
    // https: {
    //   // 证书文件路径（默认生成在项目根目录）
    //   key: fs.readFileSync('localhost+3-key.pem'),
    //   cert: fs.readFileSync('localhost+3.pem')
    // }
  }
})
